package com.huynhchihieu.webservice.endpoint;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

import com.huynhchihieu.web.service.MathService;
import com.huynhchihieu.webservice.domain.MathServiceRequest;
import com.huynhchihieu.webservice.domain.MathServiceResponse;

@Endpoint
public class MathServiceEndPoint {

    @Autowired
    MathService mathService ;

    /**
     * Check that the payload root method in endpoint for localpart and namespaceuri used these should be element name for 
     * request message in schema and namespace of the schema. Also, ensure request sent from client is in same namespace.
     * @param mathServiceRequest
     * @return
     */
	@PayloadRoot(namespace = "http://codereq.com/mathservice/schemas", localPart = "MathServiceRequest")
	public @ResponsePayload MathServiceResponse handleMathServiceRequest(
			@RequestPayload MathServiceRequest mathServiceRequest) {
		boolean isEven = getMathService().isEven(
				mathServiceRequest.getNumber().intValue());
		MathServiceResponse r = new MathServiceResponse();
		r.setIsEven(isEven);
		r.setNumber(mathServiceRequest.getNumber());
		return r;
	}

    public MathService getMathService() {
	return mathService;
    }

    public void setMathService(MathService mathService) {
	this.mathService = mathService;
    }
}